from abc import ABCMeta, abstractmethod
from sqlalchemy.orm import Session
from app.controller.model.compute import ScaleComputeRes
from app.dao.compute import modify_compute


class ComputeScaler(metaclass=ABCMeta):
    @abstractmethod
    def scale(self) -> ScaleComputeRes:
        pass


class ComputeScalerImpl(ComputeScaler):
    db: Session
    service_id: str
    #node_id: str
    compute_scale: int

    def __init__(self, db: Session, service_id: str, compute_scale: int) -> None:
        super().__init__()
        self.db = db
        self.service_id = service_id
        #self.node_id = node_id
        self.compute_scale = compute_scale

    def _modify_commit_to_db(self):
        modify_compute(self.db, self.service_id, self.compute_scale)

    def scale(self) -> ScaleComputeRes:
        self._modify_commit_to_db()

        return ScaleComputeRes(service_id=self.service_id)


def get_compute_scaler(db: Session, service_id: str, compute_scale: int) -> ComputeScaler:
    return ComputeScalerImpl(db, service_id,  compute_scale)
